home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / cert / trk3_eg / lab_opts / buffers / ed2.frm (.txt) next >
Encoding:
Visual Basic Form  |  1994-01-25  |  9.4 KB  |  319 lines

  1. VERSION 2.00
  2. Begin Form frmMPBE 
  3.    Caption         =   "Multiple Paste Buffer Editor"
  4.    ClientHeight    =   2220
  5.    ClientLeft      =   1200
  6.    ClientTop       =   3285
  7.    ClientWidth     =   6615
  8.    Height          =   2910
  9.    Left            =   1140
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   2220
  12.    ScaleWidth      =   6615
  13.    Top             =   2655
  14.    Width           =   6735
  15.    Begin CommonDialog CMDialog1 
  16.       Left            =   3480
  17.       Top             =   1560
  18.    End
  19.    Begin TextBox Text1 
  20.       Height          =   1095
  21.       Index           =   1
  22.       Left            =   3120
  23.       MultiLine       =   -1  'True
  24.       TabIndex        =   1
  25.       Top             =   240
  26.       Width           =   3255
  27.    End
  28.    Begin TextBox txtEditBox 
  29.       Height          =   1575
  30.       Left            =   0
  31.       MultiLine       =   -1  'True
  32.       ScrollBars      =   3  'Both
  33.       TabIndex        =   0
  34.       Top             =   0
  35.       Width           =   2895
  36.    End
  37.    Begin Label Label1 
  38.       Caption         =   "Paste Buffer #1"
  39.       Height          =   260
  40.       Index           =   1
  41.       Left            =   3120
  42.       TabIndex        =   2
  43.       Top             =   0
  44.       Width           =   1455
  45.    End
  46.    Begin Menu mnuFile 
  47.       Caption         =   "&File"
  48.       Begin Menu mnuFileNew 
  49.          Caption         =   "&New"
  50.       End
  51.       Begin Menu mnuFileOpen 
  52.          Caption         =   "&Open..."
  53.       End
  54.       Begin Menu mnuFileSave 
  55.          Caption         =   "&Save"
  56.       End
  57.       Begin Menu mnuFileSaveExit 
  58.          Caption         =   "Save &and Exit"
  59.       End
  60.       Begin Menu mnuFileExit 
  61.          Caption         =   "E&xit"
  62.       End
  63.    End
  64.    Begin Menu mnuEdit 
  65.       Caption         =   "&Edit"
  66.       Begin Menu mnuEditCopy1 
  67.          Caption         =   "Copy to Buffer #1"
  68.       End
  69.       Begin Menu mnuEditCopy2 
  70.          Caption         =   "Copy to Buffer #2"
  71.       End
  72.       Begin Menu mnuEditCopy3 
  73.          Caption         =   "Copy to Buffer #3"
  74.       End
  75.       Begin Menu mnuEditCopy4 
  76.          Caption         =   "Copy to Buffer #4"
  77.       End
  78.       Begin Menu mnuEditPaste1 
  79.          Caption         =   "Paste from Buffer #1"
  80.       End
  81.       Begin Menu mnuEditPaste2 
  82.          Caption         =   "Paste from Buffer #2"
  83.       End
  84.       Begin Menu mnuEditPaste3 
  85.          Caption         =   "Paste from Buffer #3"
  86.       End
  87.       Begin Menu mnuEditPaste4 
  88.          Caption         =   "Paste from Buffer #4"
  89.       End
  90.    End
  91.    Begin Menu mnuBuffer 
  92.       Caption         =   "&Buffers"
  93.       Begin Menu mnuBufferAdd 
  94.          Caption         =   "Add"
  95.       End
  96.       Begin Menu mnuBufferRemove 
  97.          Caption         =   "Remove"
  98.       End
  99.    End
  100. Option Explicit
  101. Const MAX_BUFFERS = 4
  102. 'pastecount is the number of local paste buffers
  103. 'It is 1-based.
  104. Dim pastecount As Integer
  105. 'lcv (loop control variable) is used in many places
  106. 'to drive a for/next loop
  107. Dim lcv As Integer
  108. 'dirtyflag is set to value whenever txtEditBox changes
  109. Dim dirtyflag As Integer
  110. 'fhandle and fname are used to open (and close) the file.
  111. Dim fhandle As Integer
  112. Dim fname As String
  113. Const TXT_WIDTH = .6
  114. Const SCROLL_BAR_HEIGHT = 675
  115. Const FormTitle = "Multiple Paste Buffer Editor v2.0"
  116. Sub Form_Load ()
  117.     Dim Buffers As Integer
  118.     Dim counter As Integer
  119.     Caption = FormTitle + " (untitled)"
  120.     'Size Form
  121.     frmMPBE.Left = 0
  122.     frmMPBE.Top = 0
  123.     frmMPBE.Width = Screen.Width
  124.     frmMPBE.Height = Screen.Height
  125.     'Set up the common dialog box.
  126.     CMDialog1.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*"
  127.     pastecount = 1
  128.     positionbuffers   'Positions the buffers and resizes the buffers
  129. End Sub
  130. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  131.     Dim rc As Integer
  132.     Const YES = 6
  133.     If dirtyflag Then
  134.         rc = MsgBox("Save changes before terminating?", 4, "File has changed!")
  135.         If rc = YES Then
  136.             mnuFileSave_Click
  137.         End If
  138.     End If
  139. End Sub
  140. Sub Form_Resize ()
  141.     Dim counter As Integer
  142.     txtEditBox.Width = frmMPBE.Width * TXT_WIDTH
  143.     If frmMPBE.Height - SCROLL_BAR_HEIGHT > 0 Then
  144.         txtEditBox.Height = frmMPBE.Height - SCROLL_BAR_HEIGHT
  145.     End If
  146.     For counter = 1 To pastecount
  147.         label1(counter).Left = frmMPBE.Width * TXT_WIDTH + 150
  148.         text1(counter).Left = frmMPBE.Width * TXT_WIDTH + 150
  149.     Next counter
  150. End Sub
  151. Sub mnuBuffer_Click ()
  152.     If pastecount >= MAX_BUFFERS Then
  153.         mnuBufferAdd.Enabled = False
  154.     Else
  155.         mnuBufferAdd.Enabled = True
  156.     End If
  157.     If pastecount = 1 Then
  158.         mnuBufferRemove.Enabled = False
  159.     Else
  160.         mnuBufferRemove.Enabled = True
  161.     End If
  162. End Sub
  163. Sub mnuBufferAdd_Click ()
  164.     Const DELTA = 1500
  165.     pastecount = pastecount + 1
  166.     Load label1(pastecount)
  167.     'label1(pastecount).Top = label1(pastecount - 1).Top + DELTA
  168.     label1(pastecount).Caption = "Paste Buffer #" + LTrim$(Str$(pastecount))
  169.     label1(pastecount).Visible = True
  170.     Load text1(pastecount)
  171.     'text1(pastecount).Top = text1(pastecount - 1).Top + DELTA
  172.     text1(pastecount).Visible = True
  173.     text1(pastecount).Text = ""
  174.     positionbuffers   'Positions the buffers and resizes the buffers
  175. End Sub
  176. Sub mnuBufferRemove_Click ()
  177.     'Unload the label and the text control
  178.     Unload label1(pastecount)
  179.     Unload text1(pastecount)
  180.     pastecount = pastecount - 1
  181.     positionbuffers   'Positions the buffers and resizes the buffers
  182. End Sub
  183. Sub mnuEditCopy1_Click ()
  184.     my_Copy 1
  185. End Sub
  186. Sub mnuEditCopy2_Click ()
  187.     my_Copy 2
  188. End Sub
  189. Sub mnuEditCopy3_Click ()
  190.     my_Copy 3
  191. End Sub
  192. Sub mnuEditCopy4_Click ()
  193.     my_Copy 4
  194. End Sub
  195. Sub mnuEditPaste1_Click ()
  196.     my_Paste 1
  197. End Sub
  198. Sub mnuEditPaste2_Click ()
  199.     my_Paste 2
  200. End Sub
  201. Sub mnuEditPaste3_Click ()
  202.     my_Paste 3
  203. End Sub
  204. Sub mnuEditPaste4_Click ()
  205.     my_Paste 4
  206. End Sub
  207. Sub mnuFileExit_Click ()
  208.     Dim rc As Integer
  209.     Const YES = 6
  210.     If dirtyflag Then
  211.         rc = MsgBox("Save changes before terminating?", 4, "File has changed!")
  212.         If rc = YES Then
  213.             mnuFileSave_Click
  214.         End If
  215.     End If
  216.     'Terminate
  217.     End
  218. End Sub
  219. Sub mnuFileNew_Click ()
  220.     Const YES = 6
  221.     Dim rc As Integer
  222.     If dirtyflag = True Then
  223.         rc = MsgBox("Save changes before a fresh start?", 4, "Text has changed!")
  224.         If rc = YES Then
  225.             mnuFileSave_Click
  226.         End If
  227.     End If
  228.     fname = ""
  229.     txtEditBox.Text = ""
  230.     dirtyflag = False
  231.     frmMPBE.Caption = FormTitle + " (untitled)"
  232. End Sub
  233. Sub mnuFileOpen_Click ()
  234.     Const YES = 6
  235.     Dim rc As Integer
  236.     If dirtyflag = True Then
  237.         rc = MsgBox("Save changes before opening a new file?", 4, "Text has changed!")
  238.         If rc = YES Then
  239.             mnuFileSave_Click
  240.         End If
  241.     End If
  242.     'Invoke the Dialog Box
  243.     CMDialog1.Action = 1
  244.     'If fname is empty, then exit the subroutine.
  245.     fname = CMDialog1.Filename
  246.     If fname = "" Then
  247.         Beep
  248.         Exit Sub
  249.     End If
  250.     'Build the title without a path.
  251.     frmMPBE.Caption = FormTitle + " (" + CMDialog1.Filetitle + ")"
  252.     'Get a fresh handle and read the file in.
  253.     fhandle = FreeFile
  254.     Open fname For Input As fhandle
  255.     txtEditBox.Text = Input$(LOF(fhandle), fhandle)
  256.     dirtyflag = False
  257.     Close fhandle
  258. End Sub
  259. Sub mnuFileSave_Click ()
  260.     If dirtyflag = False Then
  261.         Exit Sub
  262.     End If
  263.     'Get a fresh handle and write the file to it.
  264.     If fname = "" Then
  265.         fname = InputBox$("Enter a file name. File will be saved in " + CurDir$, "No file name available!")
  266.         frmMPBE.Caption = FormTitle + " (" + fname + ")"
  267.     End If
  268.     'Now if fname is empty, terminate the subroutine.
  269.     If fname = "" Then
  270.         Exit Sub
  271.     End If
  272.     fhandle = FreeFile
  273.     Open fname For Output As fhandle
  274.     Print #fhandle, txtEditBox.Text
  275.     Close fhandle
  276.     dirtyflag = False
  277. End Sub
  278. Sub mnuFileSaveExit_Click ()
  279.     mnuFileSave_Click
  280.     End
  281. End Sub
  282. Sub my_Copy (index As Integer)
  283.     If index > pastecount Then
  284.         Beep
  285.         MsgBox "Buffer isn't available.", 0, "Too high!"
  286.         Exit Sub
  287.     End If
  288.     If Not Screen.ActiveControl Is txtEditBox Then
  289.         MsgBox "You must have something selected in the editing window.", 0, "Nothing Selected!"
  290.         Exit Sub
  291.     End If
  292.     text1(index).Text = txtEditBox.SelText
  293. End Sub
  294. Sub my_Paste (index As Integer)
  295.     If index > pastecount Then
  296.         Beep
  297.         MsgBox "Buffer isn't available.", 0, "Too high!"
  298.         Exit Sub
  299.     End If
  300.     If Not Screen.ActiveControl Is txtEditBox Then
  301.         MsgBox "You must place the cursor in the editing window.", 0, "Not in Editing Window!"
  302.         Exit Sub
  303.     End If
  304.     txtEditBox.SelText = text1(index).Text
  305. End Sub
  306. Sub positionbuffers ()
  307.     Dim cnt As Integer
  308.     Dim frmheight As Integer
  309.     frmheight = frmMPBE.ScaleHeight - 60
  310.     For cnt = 1 To pastecount
  311.         text1(cnt).Height = frmheight / pastecount - 250
  312.         text1(cnt).Top = (cnt - 1) * frmheight / pastecount + 250
  313.         label1(cnt).Top = (cnt - 1) * frmheight / pastecount + 20
  314.     Next
  315. End Sub
  316. Sub txtEditBox_Change ()
  317.     dirtyflag = True
  318. End Sub
  319.